package cloud.misiro.spring.cloud.loadbalancer.ribbon.config;

import cloud.misiro.spring.cloud.MiniDiscoveryProperties;
import cloud.misiro.spring.cloud.loadbalancer.ribbon.MiniServerList;
import com.netflix.client.config.IClientConfig;
import com.netflix.loadbalancer.ServerList;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MiniRibbonClientConfiguration {

    @Bean
    @ConditionalOnMissingBean
    public ServerList<?> ribbonServerList(IClientConfig config, MiniDiscoveryProperties discoveryProperties) {
        MiniServerList serverList = new MiniServerList(discoveryProperties);
        serverList.initWithNiwsConfig(config);
        return serverList;
    }
}
